<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" id="html">
    <head>
        <title></title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <base href="<?= base_url(1); ?>" />
        <link type="text/css" href="css/main.css?v=<?= $config['version'] ?>" rel="stylesheet" />
    </head>
    <body>
        <?php include(VIEWPATH . 'common/main_header.php'); ?>
        <div class="datalist"><table id="flexigrid" style="display:none"></table></div>
        <script type="text/javascript">
            $(function() {
                $("#flexigrid").flexigrid($.extend(SG.flexOptions, {
                    url: '<?= site_url('general/crontab/flexigrid') ?>',
                    colModel: [
                        //{display: 'ID', name: 'id', width: '250', iskey: true},
                        {display: '<?= translate('GENERAL_CRONTAB_TYPE') ?>', name: 'type', width: '100', process: formatType},
                        {display: '<?= translate('GENERAL_CRONTAB_TITLE') ?>', name: 'title', width: '200'},
                        {display: '<?= translate('GENERAL_CRONTAB_MSG') ?>', name: 'content', width: '300'},
                        {display: '<?= translate('GENERAL_CRONTAB_MAX_EXCUTE_TIMES') ?>', name: 'maximums', width: '80', process: formatMaximums},
                        {display: '<?= translate('GENERAL_CRONTAB_EXCUTES') ?>', name: 'executes', width: '50'},
                        {display: '<?= translate('CREATETIME') ?>', name: 'createtime', width: '140', hide: true},
                        {display: '<?= translate('STARTTIME') ?>', name: 'starttime', width: 120},
                        {display: '<?= translate('EXPIRETIME') ?>', name: 'expiretime', width: 120},
                        {display: '<?= translate('RUNTIME') ?>', name: 'executetime', width: 120},
                        {display: '<?= translate('WEIGH') ?>', name: 'weigh', width: '40', hide: true},
                        {display: '<?= translate('STATUS') ?>', name: 'state', width: '40', process: formatCronState},
                        {display: '<?= translate('MANAGE') ?>', name: 'id', width: '140', sortable: false, process: formatOp},
                    ],
                    buttons: [
                        {name: 'add', displayname: "<?= translate('ADD') ?>", title: "<?= translate('ADD') ?>", bclass: 'add', onpress: multi},
                        {name: 'delete', displayname: "<?= translate('DEL') ?>", title: "<?= translate('DEL') ?>", bclass: 'delete', onpress: multi},
                        {name: 'reject', displayname: "<?= translate('CLOSE') ?>", bclass: 'reject', onpress: multi},
                        {name: 'accept', displayname: "<?= translate('OPEN') ?>", bclass: 'accept', onpress: multi},
                        {separator: true},
                    ],
                    searchitems: [
                                 {display:'<?= translate('GENERAL_CRONTAB_TITLE') ?>',name:'title'},
                                 {display:'<?= translate('GENERAL_CRONTAB_MSG') ?>',name:'content'},
                                 {display:'<?= translate('GENERAL_CRONTAB_TYPE') ?>',name:'type'},
                    			],
                    sortname: "weigh",
                    sortorder: "desc",
                }));
                SG.admin = $.extend(SG.admin, {
                    add_url: '<?= site_url("general/crontab/add/") ?>',
                    edit_url: '<?= site_url("general/crontab/edit/") ?>',
                    del_url: '<?= site_url("general/crontab/del/") ?>',
                    multi_url: '<?= site_url("general/crontab/multi/") ?>',
                    table: '{pre}crontab'
                });

                function formatType(value, id, cell, field) {
                    var typearr = <?= json_encode($typearr) ?>;
                    var arr = [];
                    $.each(typearr, function(i, j) {
                        arr.push({color: '', text: j, value: i});
                    });
                    return filterGeneral(arr, value, field);
                }

                function formatMaximums(value) {
                    return value == 0 ? "<font color=green><?= translate('NOLIMIT') ?></font>" : value;
                }

                function formatCronState(value, id, cell, field) {
                    var arr = [, {
                            color: 'green',
                            text: '<?= translate('END') ?>',
                            value: 2
                        }, {
                            color: 'orange',
                            text: '<?= translate('RUNNING') ?>',
                            value: 1
                        }, {
                            color: 'purple',
                            text: '<?= translate('WAITING') ?>',
                            value: 0
                        }, {
                            color: 'gray',
                            text: '<?= translate('EXPIRE') ?>',
                            value: -1
                        }];
                    return filterGeneral(arr, value, field);
                }
            });
        </script>
    </body>
</html>